package com.joy.vo;

import com.joy.model.User;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.text.SimpleDateFormat;

import static com.joy.common.UserType.userTypeToDesMap;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class UserInfoVO {
    private String name;
    private String school;
    private String faculty;
    private String gender;
    private String date;
    private String id;
    private String type;
    private String phone;

    public static UserInfoVO from(User user) {
        UserInfoVO userInfoVO = new UserInfoVO();
        userInfoVO.setName(user.getUserName());
        userInfoVO.setSchool(user.getSchool());
        userInfoVO.setFaculty(user.getFaculty());
        userInfoVO.setGender(user.getGender());
        // 创建一个SimpleDateFormat对象，并设置所需的日期格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

        // 将Timestamp格式化为字符串
        String formattedDate = dateFormat.format(user.getModifyTime());
        userInfoVO.setDate(formattedDate);
        userInfoVO.setId(String.valueOf(user.getId()));
        userInfoVO.setType(userTypeToDesMap.get(user.getType()));
        userInfoVO.setPhone(user.getPhone());
        return userInfoVO;
    }
}
